package ca.on.eho.qa.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import ca.on.eho.qa.applogic1.DriverBasedHelper;
import ca.on.eho.qa.util.Constants;

/**
 * @author larissa.smirnova
 * 
 * Created on: Oct-15-2014
 * Change log:
 * 
 */

public class LoginPage extends Page {
	
	private static WebElement element = null;
	private static WebDriverWait wait = null;
	
	public static By by_userIdField = By.id("userID");
	public static By by_passwordField = By.id("password");
	public static By by_loginButton = By.name("ns_7_CGAH47L0082M302B566VO730E0__login");
	public static By by_loginHeader = By.id("wptheme-applicationName");
	
	public static final String	LOGIN = "Login";
	
	
	public LoginPage(PageManager pages) {
		super(pages);		
	}
	
	@FindBy(id = "userID")
	private WebElement userIdField;
	
	@FindBy(id = "password")
	private WebElement passwordField;
	
	@FindBy(name = "ns_7_CGAH47L0082M302B566VO730E0__login")
	private WebElement loginButton;
	
	@FindBy(id = "wptheme-applicationName")
	private WebElement loginHeader;

	
	public LoginPage setUserIdField(String text) {
		userIdField.clear();	
		userIdField.sendKeys(text);	
		return this;		
	}
	
	public LoginPage setPasswordField(String text) {
		passwordField.clear();
		passwordField.sendKeys(text);	
		return this;		
	}
	
	public LoginPage clickLoginButton() {
		loginButton.click();	
		return this;		
	}
	
	
	public LoginPage ensurePageLoaded() {
		super.ensurePageLoaded();
		wait.until(ExpectedConditions.presenceOfElementLocated(by_userIdField));
		return this;		
	}
	
}
